<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Cart</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        
        <h1>
            <span class="type">Class</span>
            Cart
            
                <span class="parent">&lt;
                    
                    <a href="ApplicationRecord.html">ApplicationRecord</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../files/app/models/cart_rb.html">app/models/cart.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="#method-i-add_quantity">add_quantity</a>,
              </li>
            
              
              <li>
                <a href="#method-i-amount">amount</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="#method-i-creater">creater</a>,
              </li>
            
              
              <li>
                <a href="#method-i-customable_product_count">customable_product_count</a>,
              </li>
            
              
              <li>
                <a href="#method-i-customable_products">customable_products</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>H</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="#method-i-has_item">has_item</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>I</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="#method-i-items_count">items_count</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-add_quantity">
            
              <b>add_quantity</b>(product_id, num)
            
            <a href="../classes/Cart.html#method-i-add_quantity" name="method-i-add_quantity" class="permalink">Link</a>
          </div>

          
            <div class="description">
              
            </div>
          

          

          

          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-add_quantity_source')" id="l_method-i-add_quantity_source">show</a>
                
              </p>
              <div id="method-i-add_quantity_source" class="dyn-source">
                <pre><span class="ruby-comment"># File app/models/cart.rb, line 33</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_quantity</span>(<span class="ruby-identifier">product_id</span>, <span class="ruby-identifier">num</span>)
  <span class="ruby-ivar">@cart_item</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">items</span>.<span class="ruby-identifier">showable</span>.<span class="ruby-identifier">exist_item</span>(<span class="ruby-identifier">product_id</span>)
  <span class="ruby-ivar">@cart_item</span>.<span class="ruby-identifier">quantity</span> = <span class="ruby-ivar">@cart_item</span>.<span class="ruby-identifier">quantity</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">num</span>.<span class="ruby-identifier">to_i</span>
  <span class="ruby-ivar">@cart_item</span>.<span class="ruby-identifier">save</span>
  <span class="ruby-keyword">return</span> {<span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>, <span class="ruby-identifier">cart_item_id</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@cart_item</span>.<span class="ruby-identifier">id</span>}
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-amount">
            
              <b>amount</b>()
            
            <a href="../classes/Cart.html#method-i-amount" name="method-i-amount" class="permalink">Link</a>
          </div>

          
            <div class="description">
              
            </div>
          

          

          

          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-amount_source')" id="l_method-i-amount_source">show</a>
                
              </p>
              <div id="method-i-amount_source" class="dyn-source">
                <pre><span class="ruby-comment"># File app/models/cart.rb, line 9</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">amount</span>
  <span class="ruby-identifier">items</span>.<span class="ruby-identifier">showable</span>.<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">amount</span>}.<span class="ruby-identifier">sum</span>
  <span class="ruby-comment"># items.sum{|item| item.amount}</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-creater">
            
              <b>creater</b>(params)
            
            <a href="../classes/Cart.html#method-i-creater" name="method-i-creater" class="permalink">Link</a>
          </div>

          
            <div class="description">
              
            </div>
          

          

          

          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-creater_source')" id="l_method-i-creater_source">show</a>
                
              </p>
              <div id="method-i-creater_source" class="dyn-source">
                <pre><span class="ruby-comment"># File app/models/cart.rb, line 24</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">creater</span>(<span class="ruby-identifier">params</span>)
  <span class="ruby-ivar">@cart_item</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">items</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">params</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@cart_item</span>.<span class="ruby-identifier">save</span>
    <span class="ruby-keyword">return</span> {<span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>, <span class="ruby-identifier">cart_item_id</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@cart_item</span>.<span class="ruby-identifier">id</span>}
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">return</span> {<span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-keyword">false</span>, <span class="ruby-identifier">message</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@cart_item</span>.<span class="ruby-identifier">errors</span>.<span class="ruby-identifier">full_messages</span>.<span class="ruby-identifier">first</span>}
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-customable_product_count">
            
              <b>customable_product_count</b>()
            
            <a href="../classes/Cart.html#method-i-customable_product_count" name="method-i-customable_product_count" class="permalink">Link</a>
          </div>

          
            <div class="description">
              
            </div>
          

          

          

          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-customable_product_count_source')" id="l_method-i-customable_product_count_source">show</a>
                
              </p>
              <div id="method-i-customable_product_count_source" class="dyn-source">
                <pre><span class="ruby-comment"># File app/models/cart.rb, line 48</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">customable_product_count</span>
  <span class="ruby-identifier">customable_products</span>.<span class="ruby-identifier">count</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-customable_products">
            
              <b>customable_products</b>()
            
            <a href="../classes/Cart.html#method-i-customable_products" name="method-i-customable_products" class="permalink">Link</a>
          </div>

          
            <div class="description">
              
            </div>
          

          

          

          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-customable_products_source')" id="l_method-i-customable_products_source">show</a>
                
              </p>
              <div id="method-i-customable_products_source" class="dyn-source">
                <pre><span class="ruby-comment"># File app/models/cart.rb, line 44</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">customable_products</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">items</span>.<span class="ruby-identifier">showable</span>.<span class="ruby-identifier">customs</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-has_item">
            
              <b>has_item</b>(params)
            
            <a href="../classes/Cart.html#method-i-has_item" name="method-i-has_item" class="permalink">Link</a>
          </div>

          
            <div class="description">
              
            </div>
          

          

          

          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-has_item_source')" id="l_method-i-has_item_source">show</a>
                
              </p>
              <div id="method-i-has_item_source" class="dyn-source">
                <pre><span class="ruby-comment"># File app/models/cart.rb, line 14</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">has_item</span>(<span class="ruby-identifier">params</span>)
  <span class="ruby-ivar">@product_id</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">params</span>[<span class="ruby-value">:store_product_id</span>]
  <span class="ruby-ivar">@product_ids</span> = <span class="ruby-identifier">items</span>.<span class="ruby-identifier">showable</span>.<span class="ruby-identifier">pluck</span>(<span class="ruby-value">:store_product_id</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@product_ids</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-ivar">@product_id</span>.<span class="ruby-identifier">to_i</span>)
    <span class="ruby-identifier">add_quantity</span>(<span class="ruby-ivar">@product_id</span>, <span class="ruby-identifier">params</span>[<span class="ruby-value">:quantity</span>])
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">creater</span>(<span class="ruby-identifier">params</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-items_count">
            
              <b>items_count</b>()
            
            <a href="../classes/Cart.html#method-i-items_count" name="method-i-items_count" class="permalink">Link</a>
          </div>

          
            <div class="description">
              
            </div>
          

          

          

          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-items_count_source')" id="l_method-i-items_count_source">show</a>
                
              </p>
              <div id="method-i-items_count_source" class="dyn-source">
                <pre><span class="ruby-comment"># File app/models/cart.rb, line 40</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">items_count</span>
  <span class="ruby-identifier">items</span>.<span class="ruby-identifier">showable</span>.<span class="ruby-identifier">count</span>(<span class="ruby-value">:id</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>
